<?php
  /**
   * iJLanguageControlBlock
   *
   * The iJLanguageControlBlock class 
   *
   * @copyright Copyright (c) 2011, iJBloks Progect
   */
    class LanguageControl extends iJBlock{
        
        /**
         *
         * Class Constructuctor
         * @access public
         */
        public function __construct() {
    
        }
        
        
        /**
         * execute
         *
         * Executes the block to generate the tokens
         *
         * @return array Array with the tokens of the block
         *
         * @access public
         */
        public function execute() {
          
          $iJLanguages = iJFactory::singleton('iJLanguages');
          if(isset($_POST['create'])) {
             //$this->createBlock($_POST);
          } 
          
          if(isset($_POST['edit'])) {
            // $this->editBlock($_POST);
          } 
          
          
          
          if(isset($_REQUEST['delID'])) {
            //$this->deleteBlock($_REQUEST['delID']);
          }
         //TODO only local tokens priotity
          $page   = isset($_REQUEST['page'])                                  ? $_REQUEST['page']   : 1;
          $search = isset($_REQUEST['search']) && !empty($_REQUEST['search']) ? $_REQUEST['search'] : '';
          $langsList = $iJLanguages->getLanguageList($page, $search);
          $languages     = $langsList[0];
          $QLanguges     = $langsList[1];
          $this->addToken('languges',    $languages);         
          $this->addToken('search',      $search);
          $this->addToken('page',        $page);
          $this->addToken('delete_icon', iJHrefLink::Icon('trash', '16x16'));
          $this->addToken('edit_icon',   iJHrefLink::Icon('edit', '16x16'));
          $this->addToken('form_action', iJHrefLink::linkToLocalPage('admin_languages')); 
          $this->addToken('curLanguage', $iJLanguages->getLanguage());
          $this->addToken('languages',   $iJLanguages->getLanguagesExeptCurrent());  
          
          $this->addToken('total_items',    $QLanguges->getSize());
          $this->addToken('pages_count',    $QLanguges->getPagesCount());
          $this->addToken('prev_link',      $QLanguges->getPerviousLink($page, 'admin_languages'));
          $this->addToken('next_link',      $QLanguges->getNextLink($page, 'admin_languages'));

          return parent::execute();
        }
        
    }
?>